<?php
class User extends Eloquent{
	public $table="users";
	public static function check_login($username,$password){
		$check = User::where("username","=",$username)->get();
		$sl = $check->count();
		if($sl>0){
			$pass = 0;
			$role = 0;
			foreach ($check as $check) {
				$pass = $check->password;
				$role = $check->role;
			}
			if(Hash::check($password,$pass)){
				return $role;
			}
			else
				return 2;			
		}
		else return 2;
	}
	public static function check_username($username){
		if(User::where("username","=",$username)->count()>0)
			return false;
		else
			return true;
	}
	public static function check_email($email){
		if(User::where("email","=",$email)->count()>0)
			return false;
		else
			return true;	
	}
	public static function save_user($username,$password,$email,$sex){
		User::insert(
			array(
				"username"=>$username,
				"password"=>$password,
				"email"=>$email,
				"sex"=>$sex
			)
		);
	}
}